﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Presentation.Models.Binders
{
    public class ProjectViewModelBinding : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var model = base.BindModel(controllerContext, bindingContext) as ProjectViewModel;
            var project = model.Project;

            foreach (var detail in model.Project.Details)
            {
                detail.Project = project;
            }

            foreach (var subproject in model.Project.Subprojects)
            {
                subproject.Project = project;
            }

            foreach (var task in model.Project.Tasks)
            {
                task.Project = project;
            }

            return model;
        }
    }
}